//
//  MainCarTableViewCell.m
//  19-CarHomeWork
//
//  Created by 曹曹 on 16/8/9.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "MainCarTableViewCell.h"
#import "MainCollectionViewCell.h"
#import "GGList.h"
#import "UIImageView+DownloadImage.h"

@interface MainCarTableViewCell () <UICollectionViewDataSource, UICollectionViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;

@end

@implementation MainCarTableViewCell

- (void)layoutSubviews {
    [super layoutSubviews];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.contentSize = CGSizeMake(CGRectGetWidth(self.bounds), 0);
    _collectionView.backgroundColor = [UIColor whiteColor];
    _layout.itemSize = CGSizeMake((self.contentView.frame.size.width - 40) / 3, CGRectGetHeight(self.bounds) - 20);
    _layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (_list) {
            [self.collectionView reloadData];
        }
        //FAQ是英文Frequently Asked Questions
    });
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _list.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"main" forIndexPath:indexPath];
    ;
    cell.label.text = _list[indexPath.row].seriesname;
    [cell.imageView asyncDownloadImageWithURL:_list[indexPath.row].img completionHandler:^(NSData *data, UIImage *image) {
    }];
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
